/**
 * 
 */
package com.mc.easyexcel.write;

import java.util.List;
import java.util.Set;

import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.util.CollectionUtils;

//import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.util.StyleUtil;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;

/**
 * @author w.weizhen
 * 自定义样式
 */
public class CustomCellWriteHandler implements CellWriteHandler{
//	//标黄行宽集合
//    private Set<Integer> yellowRowIndexs;
//
//    //构造
//    public CustomCellWriteHandler(Set<Integer> yellowRowIndexs) {
//        this.yellowRowIndexs = yellowRowIndexs;
//    }
//
//    public CustomCellWriteHandler() {
//    }
//	@Override
//	public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row,
//			Head head, Integer columnIndex, Integer relativeRowIndex, Boolean isHead) {
//		// TODO Auto-generated method stub
//		
//	}
//
//	@Override
//	public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell,
//			Head head, Integer relativeRowIndex, Boolean isHead) {
//		// TODO Auto-generated method stub
//		
//	}
//
//	@Override
//	public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
//			CellData cellData, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
//		// TODO Auto-generated method stub
//		
//	}
//
//	@Override
//	public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, 
//			List<CellData> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
//	
//		//不处理第一行  
//        // 根据单元格获取workbook
//        Workbook workbook = cell.getSheet().getWorkbook();
//        //设置行高  
//        writeSheetHolder.getSheet().getRow(cell.getRowIndex()).setHeight((short)(1.4*256));
//        // 单元格策略
//        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
//        // 设置背景颜色白色
//        contentWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
//        // 设置垂直居中为居中对齐
//        contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
//        // 设置左右对齐为靠左对齐
//        contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.LEFT);
//        // 设置单元格上下左右边框为细边框
//        contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);
//        contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);
//        contentWriteCellStyle.setBorderRight(BorderStyle.THIN);
//        contentWriteCellStyle.setBorderTop(BorderStyle.THIN);
//        
//        // 创建字体实例
//        WriteFont cellWriteFont = new WriteFont();
//        // 设置字体大小
//        cellWriteFont.setFontHeightInPoints((short)12);
//        
//        contentWriteCellStyle.setWriteFont(cellWriteFont);
//        CellStyle cellStyle = StyleUtil.buildHeadCellStyle(workbook, contentWriteCellStyle);
//        cell.setCellStyle(cellStyle);
//		
//		if (!CollectionUtils.isEmpty(yellowRowIndexs)) {
//            Workbook workbookx = writeSheetHolder.getSheet().getWorkbook();
//            //CellStyle cellStylex = workbookx.createCellStyle();
//            CellStyle cellStylex = StyleUtil.buildDefaultCellStyle(workbookx);
//            
//            //字体
//            Font cellFont = workbook.createFont();
//            cellFont.setBold(true);
//            cellStylex.setFont(cellFont);
//            //标黄,要一起设置
//            cellStylex.setFillPattern(FillPatternType.SOLID_FOREGROUND); //设置前景填充样式
//            cellStylex.setFillForegroundColor(IndexedColors.YELLOW.getIndex());//前景填充色
//            
//			if (yellowRowIndexs.contains(cell.getRowIndex())&&yellowRowIndexs.contains(cell.getColumnIndex())) {
//                
//            	cell.setCellStyle(cellStylex);
//            }
//        }
//	}

}
